Add typing to _ConnectionParameters and related functions#1199
Open
DanielNoord wants to merge 8 commits intoMagicStack:masterfrom
Open
Add typing to _ConnectionParameters and related functions#1199DanielNoord wants to merge 8 commits intoMagicStack:masterfrom
_ConnectionParameters and related functions#1199DanielNoord wants to merge 8 commits intoMagicStack:masterfrom
Conversation
Contributor
Author
|
Based on review in #1198 I have swapped out the stringified annotations for non-stringified behind a I also had to rebase and force push due to merge conflicts. |
dd3b924 to
294e6bc
Compare
elprans
reviewed
Dec 18, 2024
|
|
||
| def _validate_port_spec(hosts, port): | ||
| def _validate_port_spec( | ||
| hosts: Sequence[object], port: typing.Union[int, typing.List[int]] |
Member
There was a problem hiding this comment.
Suggested change
| hosts: Sequence[object], port: typing.Union[int, typing.List[int]] | |
| hosts: typing.List[str], port: typing.Union[int, typing.List[int]] |
Contributor
Author
There was a problem hiding this comment.
I did this because of line 172. If your suggestion is correct we can remove the else branch. Since I didn't want to change the functionality of the code too much I just added what the code is able to handle instead of what it likely should be, if that makes sense.
Would you want me to change this? Or is keeping as is fine? If it is the latter, could you press the Merge button? :)
elprans
approved these changes
Dec 18, 2024
|
Would be lovely to get this merged :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds typing to an important
NamedTuplein this module that will allow using types in a lot of other functions that have a reference to this object.The final type looks very similar to what was suggested in #577 but this is based on the paths that the code can actually take. As with other PRs the strategy is simple: start with the lowest function in the call chain to see if the code can tell you what types it should accept and propagate upwards until you reach the
NamedTuple.The most controversial change is probably
_ConnectionParameters.ssl. This is because of the code path where we setsslmode = SSLMode.disable. It is a bit annoying but that code path means thatsslnever gets reassigned and therefore will be whatever_parse_connect_dsn_and_argsaccepts. We should probably change that to beNonebut I don't want to introduce behaviour changes in these PRs.The two actual runtime changes are straightforward and any mistakes in the typing we can (of course) always rectify later.